package Ar;

import java.util.Arrays;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/

//要求将以上数组中值为0的项去掉，将不为0的值存入一个新的数组，生成的新数组为： int newArr [] ={1,3,4,5,6,6,5,4,7,6,7,5} 
public class No_4 {
    public static void main(String[] args) {
        int[] oldArr= {1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
        int count = 0;
        for (int i = 0; i < oldArr.length; i++) {
            if (oldArr[i] != 0) {
                count++;
            }
        }
        int[] newArr = new int[count];
        //现在数组值全是0
        int a=0;
        for (int i = 0; i <oldArr.length; i++) {
            if (oldArr[i] != 0) {
                newArr[a]=oldArr[i];
                a++;//不为0的数字装入新的数组
            }
        }
        System.out.print(Arrays.toString(newArr));
    }
}
